<template>
    <div>
        <div class="container">
            <h2>校 友 信 息 详 情</h2>
            <el-form ref="form" :model="alumni" label-width="100px">
                <el-form-item label="校友ID">
                    <el-input v-model="alumni.alumniId" disabled></el-input>
                </el-form-item>
                <el-form-item label="校友姓名">
                    <el-input v-model="alumni.realName" disabled></el-input>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="alumni.idNumber" disabled></el-input>
                </el-form-item>
                <el-form-item label="性 别">
                    <el-input v-model="alumni.sex" disabled></el-input>
                </el-form-item>
                <el-form-item label="年 龄">
                    <el-input v-model="alumni.age" disabled></el-input>
                </el-form-item>
                <el-form-item label="出生日期">
                    <el-input v-model="alumni.birthDate" disabled></el-input>
                </el-form-item>
                <el-form-item label="在校学号">
                    <el-input v-model="alumni.stuNumber"></el-input>
                </el-form-item>
                <el-form-item label="在校角色">
                    <el-input v-model="alumni.schoolRole"></el-input>
                </el-form-item>
                <el-form-item label="学 历">
                    <el-input v-model="alumni.education" ></el-input>
                </el-form-item>
                <el-form-item label="入学日期">
                    <el-input v-model="alumni.admissionDate" ></el-input>
                </el-form-item>
                <el-form-item label="毕业日期">
                    <el-input v-model="alumni.graduationDate" ></el-input>
                </el-form-item>
                <el-form-item label="微 信">
                    <el-input v-model="alumni.wechat"></el-input>
                </el-form-item>
                <el-form-item label="Q Q">
                    <el-input v-model="alumni.qq"></el-input>
                </el-form-item>
                <el-form-item label="电子邮箱">
                    <el-input v-model="alumni.email"></el-input>
                </el-form-item>
                <el-form-item label="现居住地">
                    <el-input v-model="alumni.address"></el-input>
                </el-form-item>
                <el-form-item label="创建人">
                    <el-input v-model="alumni.createOne.nick" disabled></el-input>
                </el-form-item>
                <el-form-item label="创建时间">
                    <el-input v-model="alumni.createTime" disabled></el-input>
                </el-form-item>
                <el-form-item label="更新人">
                    <el-input :value="alumni.updateBy ? alumni.updateOne.nick : '暂无更新'" disabled></el-input>
                </el-form-item>
                <el-form-item label="更新时间">
                    <el-input :value="alumni.updateTime ? alumni.updateTime : '暂无更新'" disabled></el-input>
                </el-form-item>
            </el-form>
            <div class="saveEdit">
                <el-button type="primary" @click="saveEdit" :disabled="flagChange<2">保存修改</el-button>
            </div>
        </div>
    </div>
</template>

<script>
    import { getRequest, postRequest } from '../../api';
    import { getTime } from '../../utils/dateTimeUtil';

    export default {
        name: 'AlumniDetails',
        data(){
            return {
                alumni: {},
                userId: Number(sessionStorage.getItem('userId')),
                userNick: sessionStorage.getItem('userNick'),
                flagChange: 0
            }
        },
        created() {
            const alumniId=this.$route.query.alumniId;
            getRequest('/getAlumniDetail', {alumniId: alumniId}).then(res=>{
                if(res){
                    this.alumni=res;
                }
            })
        },
        watch: {
            alumni: {
                handler(val){
                    this.flagChange++;
                },
                deep: true
            }
        },
        methods: {
            saveEdit(){
                this.$confirm(`确定要保存对校友 "${this.alumni.realName}" 信息的修改吗？`,'提示', {type: 'warning'}).then(()=>{
                    this.alumni.updateTime=getTime(new Date());
                    this.alumni.updateBy=this.userId;
                    this.alumni.updateOne={nick: this.userNick};
                    let data=JSON.parse(JSON.stringify(this.alumni));
                    data.createOne=null;
                    data.updateOne=null;
                    postRequest('/updateAlumni', data).then(res=>{
                        if(res==='success'){
                            this.$message.success('保存成功！');
                        }else{
                            console.log('操作失败!');
                        }
                    })
                })
            }
        }
    };
</script>

<style scoped>
    h2{
        text-align: center;
        margin-bottom: 30px;
        color: #2d8cf0;
    }
    .saveEdit{
        text-align: center;
    }
    .el-form{
        width: 50%;
        margin: 0 auto;
    }
</style>